package cn.liye.pingfen.controller;

import cn.liye.pingfen.pojo.dto.ComReviewsDTO;
import cn.liye.pingfen.pojo.vo.ComReviewsVO;
import cn.liye.pingfen.response.JsonResult;
import cn.liye.pingfen.service.IComReviewsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



@RestController
@RequestMapping("/v1/comreviews")
public class ComReviewsController {
    @Autowired
    IComReviewsService iComReviewsService;

    @ApiOperation("发表评论")
    @PostMapping("/addpl")
    public JsonResult addpl(ComReviewsDTO comReviewsDTO) {
        iComReviewsService.insertComreviews(comReviewsDTO);
        return JsonResult.ok();
    }



    @ApiOperation("获取评论")
    @GetMapping("/{companyId}")
    public JsonResult listCompanyId(@PathVariable Long companyId, int pageNum, int pageSize){
        PageInfo<ComReviewsVO> list = iComReviewsService.listById(companyId,pageNum,pageSize);
        return JsonResult.ok(list);
    }



    @ApiOperation("获取总分")
    @GetMapping("/sum")
    public JsonResult sum(Long companyId){
       Double sum = iComReviewsService.selectsum(companyId);
        return JsonResult.ok(sum);
    }

    @ApiOperation("获取总人数")
    @GetMapping("/count")
    public JsonResult count(Long companyId){
        int count = iComReviewsService.selectcount(companyId);
        return JsonResult.ok(count);
    }



}
